package md.lanjing.com.uitool;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

public class MyView extends View {
    public MyView(Context context) {
        this(context, null);
    }

    public MyView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MyView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int defaultWidth = 100;
        switch (widthMode) {
            case MeasureSpec.AT_MOST:
                defaultWidth=widthSize;
                break;
            case MeasureSpec.EXACTLY:
                defaultWidth=widthSize;
                break;
            case MeasureSpec.UNSPECIFIED:
                break;
        }

        int heigthSize = MeasureSpec.getSize(heightMeasureSpec);
        int hightMode = MeasureSpec.getMode(heightMeasureSpec);
        int defaultHeight=200;
        switch (hightMode) {
            case MeasureSpec.AT_MOST:
                defaultHeight=heigthSize;
                break;
            case MeasureSpec.EXACTLY:
                defaultHeight=heigthSize;
                break;
            case MeasureSpec.UNSPECIFIED:
                break;
        }

        setMeasuredDimension(defaultWidth,defaultHeight);
    }
}
